﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>员工各类型工时统计报表</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="queryInfo.factoryname+'员工各类型工时统计报表'"></vue2-report-header>
    <div style="padding: 10px;" id="queryZone">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        :disabled="formDisabled">
        <el-form-item label="筛选时间:" prop="checkdate">
          <el-date-picker v-model="queryInfo.checkdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="员工号:">
          <el-autocomplete v-model.trim="queryInfo.employeename" placeholder="请输入员工号" :trigger-on-focus="false"
            :fetch-suggestions="searchEmployeenameAsync" :value-key="'employeename'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="姓名:">
          <el-autocomplete v-model.trim="queryInfo.fullname" placeholder="请输入姓名" :trigger-on-focus="false"
            :fetch-suggestions="searchFullnameAsync" :value-key="'fullname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="小组:">
          <el-autocomplete v-model.trim="queryInfo.teamname" placeholder="请输入小组名称" :trigger-on-focus="false"
            :fetch-suggestions="searchTeamnameAsync" :value-key="'teamname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column label="小组名称" prop="teamname" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="姓名" prop="fullname" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="员工号" prop="employeename" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="油封工时" prop="oilworktime" width="200" show-overflow-tooltip>
          <template scope="scope">{{scope.row.oilworktime}} 小时</template>
        </el-table-column>
        <el-table-column label="批产工时" prop="pichanworktime" width="200" show-overflow-tooltip>
          <template scope="scope">{{scope.row.pichanworktime}} 小时</template>
        </el-table-column>
        <el-table-column label="临时工时" prop="sgdworktime" width="200" show-overflow-tooltip>
          <template scope="scope">{{scope.row.sgdworktime}} 小时</template>
        </el-table-column>
        <el-table-column label="工时汇总" prop="totalworktime" width="200" show-overflow-tooltip>
          <template scope="scope">{{scope.row.totalworktime}} 小时</template>
        </el-table-column>
      </el-table>
      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { getParams, fetchSuggestion, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactoryInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        total: 0,
        loading: false,
        loadingText: '数据查询中...',
        queryInfo: {
          factoryname: '',
          factoryid: '',
          fullname: '',
          employeename: '',
          checkdate: ''//筛选时间
        },
        dataList: [],
        userInfo: {},
        formDisabled: false,
        rules: { checkdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询用户姓名
        searchFullnameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEmployeeAsync', name: 'fullname', value, callback, triggerLength: 1 })
        },
        // 查询员工号
        searchEmployeenameAsync(value, callback) {
          fetchSuggestion({ actionName: 'getEmployeeAsync', name: 'employeename', value, callback, triggerLength: 1 })
        },
        // 查询小组名称
        searchTeamnameAsync(value, callback) {
          let restConfig = { factoryid: this.queryInfo.factoryid };
          fetchSuggestion({ actionName: 'getTeamNameAsync', name: 'teamname', value, callback, triggerLength: 1, restConfig })
        },
        async getData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.loading = true;
              this.loadingText = '数据加载中...';
              const { data: { data, meta, total } } = await axios.post('../handler/report/ZSEmployeeAllTypeWorktimeReport.ashx?action=getData', {
                type: 'getData',
                ...this.queryInfo
              })
              this.loading = false;
              if (meta.status === 500) {
                return this.$message.error(meta.msg);
              }
              this.dataList = data;
            }
          })
        },
        // 导出
        async getExportExcel() {
          const config = {
            url: '../handler/report/ZSEmployeeAllTypeWorktimeReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        }
      },
      async mounted() {
        const startOfMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.checkdate = [startOfMonth, endOfMonth];
        const factoryid = Decrypt(getParams('factoryid'));
        const factoryInfo = await getFactoryInfo({ factoryid, isMapping: '是' });
        const { factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        document.title = factoryname + '员工各类型工时统计报表';
      }
    })
  </script>
</body>

</html>